<template>
  <div class="container">
    <global-header :user="currentUser"></global-header>
    <!-- <column-list :list="list"></column-list> -->
    <form action="">
      <div class="mb-3">
        <label for="exampleInputEmail1" class="form-label">邮箱地址</label>
        <validate-input :rules="emailRules" v-model="emailVal" placeholder="请输入邮箱地址" type="text"></validate-input>
      </div>
      <!-- <div class="mb-3">
        <label for="exampleInputEmail1" class="form-label">邮箱地址</label>
        <input type="email" class="form-control" v-model="emailRef.val" @blur="validateEmail">
        <div class="form-text" v-if="emailRef.error">{{ emailRef.message }}</div>
      </div> -->
      <div class="mb-3">
        <label for="exampleInputPassword1" class="form-label">密码</label>
        <!-- <input type="password" class="form-control"> -->
        <validate-input :rules="passwordRules" v-model="passwordVal" placeholder="请输入密码" type="password"></validate-input>
      </div>
    </form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
// 此处全局引入，其他文件不用再引入直接可用
import 'bootstrap/dist/css/bootstrap.min.css'
// import ColumnList from './components/ColumnList.vue'
import GlobalHeader from './components/GlobalHeader.vue'
import ValidateInput from './components/ValidateInput.vue'
import { ColumnProps } from './types/ColumnPropsType'
import { UserProps } from './types/UserPropsType'
import { RulesProp } from './types/RulePropsType'
const testData: ColumnProps[] = [
  {
    id: 1,
    title: '333',
    description: '222'
    // avatar: 'qwe'
  },
  {
    id: 2,
    title: '333',
    description: '222'
    // avatar: 'qwe'
  },
  {
    id: 1,
    title: '333',
    description: '222'
    // avatar: 'qwe'
  },
  {
    id: 1,
    title: '333',
    description: '222'
    // avatar: 'qwe'
  }
]
const currentUser: UserProps = {
  isLogin: true,
  name: 'hello'
}

export default defineComponent({
  name: 'App',
  // ColumnList,
  components: { GlobalHeader, ValidateInput },

  setup() {
    const emailRef = reactive({
      val: '',
      error: false,
      message: ''
    })
    const emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/
    const emailVal = ref('')
    const emailRules:RulesProp = [
      { type: 'required', message: '电子邮箱地址不能为空' },
      { type: 'email', message: '请输入正确的电子邮箱' }
    ]
    const passwordVal = ref('')
    const passwordRules: RulesProp = [
      { type: 'required', message: '密码不能为空' }
    ]
    const validateEmail = () => {
      if (emailRef.val.trim() === '') {
        emailRef.error = true
        emailRef.message = 'can not be empty'
      } else if (!emailReg.test(emailRef.val)) {
        emailRef.error = true
        emailRef.message = 'should be valid email'
      } else {
        emailRef.error = false
        emailRef.message = ''
      }
    }
    return {
      list: testData,
      currentUser,
      emailRef,
      validateEmail,
      emailRules,
      emailVal,
      passwordVal,
      passwordRules
    }
  }
})
</script>

<style></style>
./types/ColumnPropsType
